<template>
  <div>
    <el-container>
      <el-header>
        <span>求职经验</span>
      </el-header>
    </el-container>
    <div class="graduate-info">
      <!-- 搜索框 -->
      <div class="campus-search">
        <el-form label-width="45px" v-model="searchForm" :inline="true">
          <el-form-item>
            <el-input
              type="text"
              placeholder="你想知道什么呢"
              v-model="searchForm.searchContent"
              style="width: 150px; margin-left: 30px; margin-top: 45px"
              auto-complete="off"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="text" style="margin-top: 45px">筛选</el-button>
          </el-form-item>
          <el-form-item>
            <el-select
              v-model="searchForm.searchType"
              placeholder="类型"
              style="width: 80px; margin-top: 45px"
            >
              <el-option label="全部" value="全部"></el-option>
              <el-option label="简历" value="简历"></el-option>
              <el-option label="面试" value="面试"></el-option>
              <el-option label="笔试" value="笔试"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button
              plain
              type="primary"
              icon="el-icon-search"
              style="margin-top: 45px"
              @click="search"
            ></el-button>
          </el-form-item>
        </el-form>
      </div>
      <!-- 分隔符 -->
      <el-divider><i class="el-icon-share"></i></el-divider>
      <div class="campus-graduate-share">
        <el-card class="box-card" v-for="item in list" :key="item.sid">
          <div slot="header" class="clearfix">
            <span>{{ item.types }}</span>
            <el-badge
              :value="item.likes"
              style="float: right; padding: 3px 0; color: red"
            >
              <el-button
                style="float: right; padding: 3px 0; color: red"
                type="primary"
                plain
                @click="like(item.sid)"
                >点个赞</el-button
              >
            </el-badge>
          </div>
          <div class="text">
            <el-input
              type="textarea"
              readonly
              v-model="item.content"
            ></el-input>
          </div>
        </el-card>
      </div>
    </div>
    <el-container>
      <el-footer>
        <div>
          <span>专注于互联网校招</span>
        </div>
      </el-footer>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "RecommendGraduateexperience",

  data() {
    return {
      list: [],
      searchForm: {
        searchContent: "",
        searchType: "",
      },
      likeForm: {
        sid: 0,
      },
    };
  },

  mounted() {
    this.loadList();
  },

  methods: {
    // 加载数据
    loadList() {
      this.$axios
        .post("/shares/queryShares")
        .then((res) => {
          if (res.data.result != null) {
            this.list = res.data.result;
          } else {
            return;
          }
        })
        .catch((error) => {
          console.log(error);
          this.$message({
            message: "系统错误!!!",
            type: "error",
          });
        });
    },
    // 根据条件搜索分享
    search() {
      // 1搜索条件为空
      if (
        this.searchForm.searchContent === "" &&
        this.searchForm.searchType === ""
      ) {
        this.loadList();
        return;
      }
      // 2条件为全部
      if (
        this.searchForm.searchContent === "" &&
        this.searchForm.searchType === "全部"
      ) {
        this.loadList();
        return;
      }
      this.$axios
        .post("/shares/search", this.searchForm)
        .then((res) => {
          if (res.data.result != null) {
            this.list = res.data.result;
          }
        })
        .catch((error) => {
          console.log(error);
          this.$message({
            message: "系统错误!!!",
            type: "error",
          });
        });
    },
    // 点赞
    like(val) {
      this.likeForm.sid = val;
      this.$axios
        .post("/shares/like", this.likeForm)
        .then((res) => {
          var response = res.data.desc;
          if (response === "点赞失败") {
            this.$message({
              message: "点赞失败",
              type: "error",
            });
            return;
          } else if (response === "点赞成功") {
            this.$message({
              message: "点赞成功",
              type: "success",
            });
            this.loadList();
          }
        })
        .catch((error) => {
          console.log(error);
          this.$message({
            message: "系统错误!!!",
            type: "error",
          });
        });
    },
  },
};
</script>

<style scoped>
.el-header {
  background-color: #409eff;
  color: white;
  line-height: 60px;
}

.el-footer {
  background-color: #409eff;
  color: white;
  line-height: 60px;
}

.el-footer div {
  margin-left: 43%;
}

.graduate-info {
  margin-top: 10px;
  margin-bottom: 10px;
  height: 480px;
  background: whitesmoke;
  /* background-image: url(https://img2.baidu.com/it/u=2699034911,1369297825&fm=253&fmt=auto&app=138&f=JPEG?w=890&h=500); */
  /* background-size: 1355px 480px; */
  overflow: auto;
}

.box-card {
  width: 650px;
  height: 160px;
  margin-right: 12px;
  margin-bottom: 10px;
}

.text {
  font-size: 14px;
}

.campus-graduate-share {
  display: flex;
  flex-wrap: wrap;
}
</style>
